package com.hhit.bigscreenbackmanage.controller.jdgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.common.Response;
import com.hhit.bigscreenbackmanage.service.jdgl.TJdglDwjsjdjhService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/jdglImportController")
public class JdglImportController {
    private static Logger log = LoggerFactory.getLogger(JdglImportController.class);

    @Autowired
    private TJdglDwjsjdjhService tJdglDwjsjdjhService;

    @PostMapping("/importExcel")
    public Response importExcel(@RequestParam("file") MultipartFile[] file, @RequestParam("propName") String propName,@RequestParam("dataTime") String dataTime) {
        Map<String, Object> stringObjectMap = new HashMap<>();
        if ("dwjsjdjhColumnName".equals(propName)) {
            stringObjectMap = tJdglDwjsjdjhService.importDwjsjdjh(propName, file, dataTime);
        }
        if ("nmggzColumnName".equals(propName)) {
            stringObjectMap = tJdglDwjsjdjhService.importNmggz(propName, file, dataTime);
        }

        Boolean flag = (Boolean)stringObjectMap.get("flag");
        if(flag){
            return Response.createResponseBySuccess("导入成功",null);
        }else {
            return Response.createResponseByError("导入失败:"+null);
        }

    }

    /**
     * 导入超长工期项目
     * @param file
     * @param propName
     * @return
     */
    @PostMapping("/importCcgq")
    public Response importCcgq(@RequestParam("file") MultipartFile[] file, @RequestParam("propName") String propName) {
        Map<String, Object> stringObjectMap = new HashMap<>();
        if ("ccgqColumnName".equals(propName)) {
            stringObjectMap = tJdglDwjsjdjhService.importCcgq(propName, file);
        }
        Boolean flag = (Boolean)stringObjectMap.get("flag");
        if(flag){
            return Response.createResponseBySuccess("导入成功",null);
        }else {
            return Response.createResponseByError("导入失败:"+null);
        }
    }

    /**
     * 查询超长工期项目
     * @param jsonObject
     * @return
     */
    @PostMapping("/queryCcgq")
    public Response queryCcgq(@RequestBody JSONObject jsonObject) {
        try {
            Map<String, Object> stringObjectMap = tJdglDwjsjdjhService.queryCcgq(jsonObject);
            return Response.createResponseBySuccess("查询成功",stringObjectMap);
        }catch (Exception e){
            return Response.createResponseByError("查询失败:"+e.getMessage());
        }
    }

    /**
     * 查询年度计划
     * @param jsonObject
     * @return
     */
    @PostMapping("/queryNdjh")
    public Response queryNdjh(@RequestBody JSONObject jsonObject) {
        try {
            Map<String, Object> stringObjectMap = tJdglDwjsjdjhService.queryNdjh(jsonObject);
            return Response.createResponseBySuccess("查询成功",stringObjectMap);
        }catch (Exception e){
            return Response.createResponseByError("查询失败:"+e.getMessage());
        }
    }
}
